home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
BBS
/
MUBBS
/
New Msgs.cpt
/
New msgs
/
New Messages Module.c
next >
Wrap
C/C++ Source or Header
|
1992-03-09
|
6KB
|
215 lines
/*
* New Messages Module - by Myles Wakeham
*
* (C)1991 Myles Wakeham - Please see the file "COPYRITE.MGW"
*
* ))) Version Changes (((
* --Version-------------Notes-----------------------------------------------------------------
* Initial Version based on Discussions in V1.1 MUBBS
*
* This program may not be sold for profit!
* The source code is being release for educational purposes only.
* I take no responsibility for any damage resulting from this code.
*/
#define INMAIN
#include "MUBBS Module.h"
#include <SetUpA4.h>
#define NOLINES 7
#define DISTMAX 50
#define LEN 80
pascal void main(int mode1, struct GS *G1, Ptr P1);
int NewMessages(void);
int count_recs(char filename[]);
pascal void main (mode1,G1,P1) /* called from the main routines, and what mode to be in */
int mode1;
struct GS *G1; /* we point to the "global" struct in the Main Module here */
Ptr P1; /* we ignore this pointer, we do not use it at all */
{
Handle temph;
float version = 1.0; /* what version of MUBBS you are compatable with IE: 1.0 and above
MAKE SURE YOU ARE COMPATABLE BEFORE SETTING THIS LESS THAN THE
VERSION OF MUBBS YOU ARE DEVELOPING THIS FOR ! */
RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
mode[u]=mode1; /* set up our mode so that you can read it anywhere */
switch (mode[u]) { /* any un-handled modes return error from this module */
/* modes are
0= Return the programmers name and the module's type & version only.
1= Bye bye call, if you returned 99 for a init call, you
get called when the program quits with mode=1.
You should do a "unlock" to release your module's memory space
and unlock any memory you allocated.
2= Normal call, no pointer passed.
3= Call with a pointer to a data struct (for passing data to a module).
98= do a version check against MUBBS version.
*/
case 2:
NewMessages();
G->moduleresult=0;
break;
case 98:
versionck(version); /* just return after this call, don't modify anything */
break;
case 0:
strcpy (G->programmer,"Myles Wakeham"); /* show the programmer's name up to 20 chars*/
strcpy (G->modtype,"New Msg V1.0"); /* module type & version up to 30 chars
the TYPE isn't always the name! */
G->moduleresult=0; /* if this was also a init call we need close call put 99 here */
break;
default:
G->moduleresult=1; /* return bad code */
};
HUnlock(temph); /* unlocks this module, do this ! */
RestoreA4(); /* call this when you are all done */
}
/**** * * * -NewMessages()- * * * * ****/
NewMessages()
{
FILE *stream1, *stream2;
char str[80];
char Myusername[LEN];
char filename[65];
char msgcountfile[LEN];
char left_half[LEN];
char msgfile[LEN];
static char distgroups[DISTMAX] [LEN];
int count;
int firsttime;
int lastcount;
int msgsread;
int linecount;
int actualmsgs;
if (!G->online[u]) return; /* Log out if hang up */
loguser(G->modulename[u]); /* write to log file */
strcpy(filename,":Dis:");
strcat(filename,G->modulename[u]);
strcat(filename,".intro");
print("C> Line %d %s, at: %s\n",(u+1),G->username[u],G->modulename[u]);
send (G->CR[u]);
sendtext(filename);
firsttime=TRUE;
/* Now intialize the distgroups array */
for(count=0;count<=DISTMAX-1;count++)
distgroups[count][0]='\0';
/* Load the distgroups array with the content of distlist */
if ((stream1 = fopen(":bbssupport:dislist","r")) == NULL)
{
send("]ERROR -43 Cannot open :bbssupport:dislist]");
print("ERROR - Cannot open :bbssupport:dislist \n");
}
else
{
for(count=0;count<=DISTMAX-1;count++) {
if (fscanf(stream1,"%80[^\n]\n",distgroups[count]) == EOF) break; /* end on EOF */
}
/* Save the Count variable */
lastcount=count;
fclose(stream1);
for(count=0;count<=lastcount-1;count++)
{
/* Establish Message Count File Name */
strcpy(msgcountfile,":Dis:");
strcpy(Myusername,G->username[u]);
strcat(msgcountfile,Myusername);
strcat(msgcountfile,distgroups[count]);
strcat(msgcountfile,".data");
/* Establish Messages file name */
strcpy(msgfile,":Dis:");
strcat(msgfile,distgroups[count]);
strcat(msgfile,".text");
/* Now open the files and check for new records */
if ((stream2 = fopen(msgcountfile,"r")) == NULL)
msgsread=0;
else
{
if(fgets(str,80,stream2) != NULL)
{
sscanf(str,"%d",&msgsread);
}
fclose(stream2);
}
/* Count the number of messages in the discussions files */
actualmsgs = count_recs(msgfile);
if(actualmsgs>=0)
{
/* Check the actual number of messages with the */
/* number of messages read and report new messages */
if(actualmsgs>msgsread)
{
if(firsttime)
{
send("]Here's the messages you haven't read...]]");
firsttime=FALSE;
}
if(actualmsgs-msgsread<2)
send("There is %d new message in %s]",
actualmsgs-msgsread, distgroups[count]);
else
send("There are %d new messages in %s]",
actualmsgs-msgsread, distgroups[count]);
}
}
}
send("]]End of List.]]");
}
}
int count_recs(filename)
char filename[];
{
FILE *stream10;
int rec_count;
char str1[81];
char squiglyStr[81];
int p;
/* Open the file and count the records */
strcpy(squiglyStr,"~\n");
if ((stream10 = fopen(filename,"r")) == NULL)
{
rec_count=(-1);
}
else
{
rec_count=0;
while(fgets(str1,80,stream10) != NULL)
{
if (strcmp(str1,squiglyStr)==0)
{
rec_count++;
}
otheruser(FALSE);
}
fclose(stream10);
}
return(rec_count);
}